prefix=@prefix@
CFLAGS = @CFLAGS@
CFLAGS += -I.

CC=gcc $(CFLAGS)
MODCFLAGS = -Wall -O2 -DMODULE -D__KERNEL__ -DLINUX
PROG = gb gbk big5 jis kscm

all: $(PROG)

# GB
gb: sencode-gb.mo 
	ld -m elf_i386 -r sencode-gb.mo -o sencode-gb.o
sencode-gb.mo: sencode-gb.c /usr/include/linux/version.h
	$(CC) $(MODCFLAGS) -c sencode-gb.c -o sencode-gb.mo

# GBK
gbk: sencode-gbk.mo
	ld -m elf_i386 -r sencode-gbk.mo -o sencode-gbk.o
sencode-gbk.mo: sencode-gbk.c /usr/include/linux/version.h
	$(CC) $(MODCFLAGS) -c sencode-gbk.c -o sencode-gbk.mo

# Big5 
big5: sencode-big5.mo 
	ld -m elf_i386 -r sencode-big5.mo -o sencode-big5.o
sencode-big5.mo: sencode-big5.c /usr/include/linux/version.h
	$(CC) $(MODCFLAGS) -c sencode-big5.c -o sencode-big5.mo

# JIS
jis: sencode-jis.mo
	ld -m elf_i386 -r sencode-jis.mo -o sencode-jis.o
sencode-jis.mo: sencode-jis.c /usr/include/linux/version.h
	$(CC) $(MODCFLAGS) -c sencode-jis.c -o sencode-jis.mo

# JIS
kscm: sencode-kscm.mo
	ld -m elf_i386 -r sencode-kscm.mo -o sencode-kscm.o
sencode-kscm.mo: sencode-jis.c /usr/include/linux/version.h
	$(CC) $(MODCFLAGS) -c sencode-kscm.c -o sencode-kscm.mo

clean:
	rm -f a.out *.bak *.o core *~ sencode-gb.mo $(PROG)

distclean: clean
	rm -f Makefile
	rm -f *.h

install: all
	mkdir -p /lib/modules/`uname -a|awk '{print $$3}'`/misc
	cp -f $(PROG) /lib/modules/`uname -a|awk '{print $$3}'`/misc

